package com.lavida.common.utils;

import java.util.Scanner;

public class CalcRate {
	public static final double base = 5000.00;// 纳税基准
	static double rateAmount = 0;// 每月税额
	static double beforeAmount = 0;// 税前金额
	static double totlerate = 0;// 累计税额
	static double[] rate;// 税率
	static double p = 0;// 专项扣除
	static double q = 0;// 速算扣除
	static double n = 0;// 五险一金扣除

	static int month = 1;// 月份
	static double[][] rates = { { 0, 0, 0 }, { 36000, 0.03, 0 },
			{ 144000, 0.1, 2520 }, { 3000000, 0.2, 16920 },
			{ 420000, 0.25, 31920 }, { 660000, 0.3, 52920 },
			{ 960000, 0.35, 85920 }, { 999999999, 0.45, 181920 } };

	public static double[] getRate(double totale) {
		double[] rate = { 36000, 0.03, 0 };
		for (int i = 1; i < rates.length; i++) {
			if (totale <= rates[0][0]) {
				rate = rates[0];
			} else if (totale > rates[i - 1][0] && totale <= rates[i][0]) {
				rate = rates[i];
				break;
			}

		}

		return rate;

	}

	public static double inputDouble(String message) {
		double input = -1;
		while (true) {
			System.out.println(message);
			try {
				Scanner in = new Scanner(System.in);
				input = in.nextDouble();
			} catch (Exception e) {
			}
			
			if (input < 0) {
				System.out.println("请输入一个正数值..");
			} else {
				break;
			}
		}
		return input;
	}

	public static int inputMonth() {
		int input = -1;
		while (true) {
			System.out.println("请输入月份:");
			try {
				Scanner in = new Scanner(System.in);
				input = in.nextInt();
			  } catch (Exception e) {
			}
			
			if (input < 1 || input >12) {
				System.out.println("请输入一个正确月份..");
			} else {
				break;
			}
		}
		return input;
	}
	//计算本月缴纳税额
	public static Double geshui(Double beforeAmounts,Double wuxian,Double qi,int months) {
			rateAmount = 0;
			totlerate = 0;
			System.out.println("-----------个税计算-------------");
			/*beforeAmount = inputDouble("请输入每月税前金额：");   //传来的值
			n = inputDouble("请输入五险一金扣除金额：");				//传来的值
			q = inputDouble("请输入专项扣除金额：");				//传来的值
			month = inputMonth();*/
			for(int i = 1;i<= months;i++){
			 double amount = (beforeAmounts-wuxian-qi-base)*i;   //纳税基准
			 rate  = getRate(amount);							//获取税收标准
			 rateAmount = Math.round(( amount * rate[1])*100)/100 - rate[2]- totlerate;
			 System.out.println("第"+i+"月:应纳税金额："+amount+",税率："+rate[1]+",速算扣除金额："
			 +rate[2]+",往月纳税金额合计："+totlerate+",本月应缴税额："+rateAmount);
			 totlerate = totlerate+rateAmount;
			}
			 System.out.println(months+"应缴税额"+rateAmount);
			return rateAmount;
		
	}
	public static void main(String[] args) {
		Double geshui =  geshui(7500.0, 850.0, 0.0, 1);
		System.out.println(geshui);
	}
}
